package com.futures.questionbank.adapter;

import android.content.Context;
import android.text.TextUtils;

import com.futures.questionbank.R;
import com.futures.questionbank.db.table.problem;
import com.futures.questionbank.db.table.problem_Table;
import com.futures.questionbank.db.table.section;
import com.github.lzyzsd.circleprogress.DonutProgress;
import com.raizlabs.android.dbflow.sql.language.SQLite;

import java.text.DecimalFormat;
import java.util.List;

public class SectionAdpter extends BaseRecycleAdapter<section> {
    private List<section> dataList;
    private Context mContext;
    private int value;
    private String a;
    private BaseViewHolder.onItemCommonClickListener commonClickListener;



    public SectionAdpter(Context context, List<section> dataList, int value, BaseViewHolder.onItemCommonClickListener commonClickListener) {
        super(context, dataList, R.layout.itme_chapter_list4);
        this.dataList = dataList;
        this.commonClickListener = commonClickListener;
        this.value = value;
        this.a = a;
        mContext = context;
    }

    @Override
    public void bindData(BaseViewHolder holder, section data) {
        holder.setText(R.id.tv_management, data.getTitle()).setCommonClickListener(commonClickListener);
      //  ImageView iv = (ImageView)holder.getView(R.id.iv);
       // iv.setImageResource(R.mipmap.jin);
        /*holder.getView(R.id.tv_lianxi).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });*/
        DonutProgress process = (DonutProgress)holder.getView(R.id.donut_progress);

         List<problem> problems = SQLite.select().from(problem.class).where(problem_Table.exam_id.eq(data.getExam_id())).queryList();
                int i = 0;
                for (problem problem : problems) {
                    if(!TextUtils.isEmpty(problem.getMy_answer())){
                        i++;
                    }
                }
        DecimalFormat df = new DecimalFormat("#.00");
        String a = df.format((float)i/problems.size());
        process.setProgress(Float.valueOf(a)*100);
            if (data.getExam_id() == value){
            // DecimalFormat fnum = new DecimalFormat("##0.00");
        }
    }
}
